package com.dbqn.zhao.service.impl;

import com.dbqn.zhao.entity.User;
import com.dbqn.zhao.service.BaseService;
import com.dbqn.zhao.service.UserService;

import java.util.List;
import java.util.Scanner;

public class RegisterServiceImpl implements BaseService, UserService {
          User user=new User();
    @Override
    public List execute(List list) {


        Scanner sc=new Scanner(System.in);

       for(;;){

           System.out.println("请输入登录名：");
           String name=sc.next();
           System.out.println("请输入密码：");
           String password=sc.next();
           System.out.println("请再次输入密码：");
           String password2=sc.next();

           //判断两次输入密码是否一致
           if(password.equals(password2)){
           }else{
               System.out.println("两次密码输入不一致请重新输入！");
               continue;
           }

           //判断密码长度和登录名是否为0
           if(name.trim().length()==0 && password.trim().length()==0){
               System.out.println("名称或者密码不能为空！");
               continue;
           }

           user.setName(name);
           user.setMima(password);

           int result=insert(list);

           if(result==1){
               System.out.println("注册成功！");
               list.add(user);
               System.out.println(user.getName());
               System.out.println(user.getMima());
               return list;
           }else{
               System.out.println("注册失败！已经注册该用户了！");
               break;
           }

       }


        return null;

    }



    @Override
    public int insert(List list) {

        for (int i = 0; i <list.size() ; i++) {

            User user1=(User) list.get(i);
            if(user1.getName().equals(user.getName())){
                return 0;
            }
        }
        return 1;


    }

    @Override
    public User login(List list,User user) {
        return null;
    }


}
